package com.mjfeed.dao;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import com.mjfeed.bean.ShippingMethodJSON;
import com.mjfeed.util.DBHelper;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
/**
 * 配送方式
 * @author zhaominglei
 * @date 2014-12-23
 * 
 */
public class ShippingMethodDao extends BaseDao {
	private static final String TABLE_NAME = "feed_shipping_method";
	
	public int getCount(Context context) {
		return getCount(context, TABLE_NAME);
	}
	
	public void deleteAll(Context context) {
		deleteAll(context, TABLE_NAME);
	}
	
	public List<ShippingMethodJSON> getAll(Context context) {
		List<ShippingMethodJSON> recordList = new ArrayList<ShippingMethodJSON>();
		SQLiteDatabase db = DBHelper.getInstance(context).getReadableDatabase();
		Cursor cursor = db.query(TABLE_NAME, null, null, null, null, null, null);
		while(cursor.moveToNext()) {
			ShippingMethodJSON shippingMethodJSON = new ShippingMethodJSON();
			shippingMethodJSON.setShippingMethodId(cursor.getLong(cursor.getColumnIndex("shippingmethodid")));
			shippingMethodJSON.setOrders(cursor.getInt(cursor.getColumnIndex("orders")));
			shippingMethodJSON.setName(cursor.getString(cursor.getColumnIndex("name")));
			shippingMethodJSON.setFirstWeight(cursor.getInt(cursor.getColumnIndex("firstweight")));
			shippingMethodJSON.setFirstPrice(new BigDecimal(cursor.getDouble(cursor.getColumnIndex("firstprice"))));
			shippingMethodJSON.setContinueWeight(cursor.getInt(cursor.getColumnIndex("continueweight")));
			shippingMethodJSON.setContinuePrice(new BigDecimal(cursor.getDouble(cursor.getColumnIndex("continueprice"))));
			shippingMethodJSON.setIcon(cursor.getString(cursor.getColumnIndex("icon"))); 
			shippingMethodJSON.setDescription(cursor.getString(cursor.getColumnIndex("description")));
			recordList.add(shippingMethodJSON);
		}
		cursor.close();
		return recordList;
	}
}
